﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "NdbObjectSchematic.h"
#include "IExternalData.h"
#include "IStructurePlateHole.h"
#include "DbDataSchema.h"
#include "RegenDataSchema.h"

namespace gcmp
{
    class IModelLine;
    class IParameter;

    class StructurePlateHole : public NdbObjectSchematic, public IExternalData, public IStructurePlateHole
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, StructurePlateHole, gcmp::NdbObjectSchematic, AAB75FA8 - F913 - 4885 - 9EFA - B24814E0057D, gmstructure, IExternalData)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(ConcreteStrengthGradeType, ConcreteStrengthGrade)
            ARR_DATA(ElementId, ProfileIds)
            DATA_REGEN(Bool, PositionValidity)
        DBOBJECT_DATA_END

    public:
        static StructurePlateHole* Create(const StructurePlateHoleGeometryInput* pInput);
        static StructurePlateHole* Create(const StructurePlateHoleElementInput* pInput);

        static StructurePlateHole* Edit(const StructurePlateHoleEditGeometryInput* pInput);
        static StructurePlateHole* Edit(const StructurePlateHoleEditElementInput* pInput);

        static StructurePlateHole* Get(IInstance* pInstance);
        static const StructurePlateHole* Get(const IInstance* pInstance);

    public:
        DECLARE_STRUCTURE_INSTANCE_METHODS
        virtual const std::vector<ElementId>& GetProfileIds() const override { return GetProfileIds__(); }
        virtual OwnerPtr<IPolygon> GetProfilePolygon() const override;
        virtual const IStructurePlate* GetHost() const override;

    public:
        // 继承自 IExternalData
        virtual bool SetOwnerElement(IElement* pOwnerElement) override { m_pOwnerElement = pOwnerElement; return true; }
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }
        virtual NdbObject* GetTopOwnerObject() const override;

        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;
        virtual void ReportParents(IElementParentReporter& reporter) const override;
        virtual void GetCalculators(ICalculatorCollection* calculators) const override;

        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg = nullptr) override;
        virtual bool IsParameterModifiable(int paramDefId) const override;

        virtual void Report(const gcmp::ICopyContext & copyContext, gcmp::ICopyStrategyReporter& reporter) const override;
        virtual void UpdateAfterCopy(const ICopyContext& copyContext) override {};
        virtual void UpdateForWeakParentCopied(const IDocument* pDocumentFrom, const IElement* pSource, const IElement* pCopy) const override {};
        virtual bool ShouldBeCopiedTogether(const ICopyContext & copyContext) const override { return true; };
        virtual bool IsStrongParentsNeedCopied(void) const override { return true; };
        virtual bool CanBeCopied(std::wstring* pErrorMessage) const override { return true; };
        virtual bool Transform(const Matrix4d& matrix) override;

        IDocument* GetDocument() const;
        ElementId GetOwnerElementId() const;
        bool UpdatePlateHoleProfiles(const std::vector<IModelLine*> profileCurves);
    };
}
